<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: navigation_main.php 502 2014-01-31 15:50:06Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 502 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2014-01-31 15:50:06 +0000 (Fri, 31 Jan 2014) $
*
* 	http://www.edv-mueller.com
*
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

$box_smarty = new Smarty();

$box_name = 'navigation_main';

if (!CacheCheck() && !FORCE_CACHE) {
	$cache = false;
	$box_smarty->caching = false;

} else {
	$cache = true;
	$box_smarty->caching = true;
	$box_smarty->cache_lifetime = CACHE_LIFETIME;
	$box_smarty->cache_modified_check = CACHE_CHECK;
	$cache_id = 'box_'.$box_name.'_'.$_SESSION['language'].'_'.$_SESSION['customers_status']['customers_status_id'].'_'.$_GET['cPath'];
}

if(!$box_smarty->isCached(CURRENT_TEMPLATE.'/boxes/box_'.$box_name.'.html', $cache_id) || !$cache){
	require_once(DIR_FS_INC.'inc.count_products_in_category.php');
  require_once(DIR_FS_INC.'functions.image.php');
  $image_paths = getImagePaths(DIR_WS_CATEGORIES_IMAGES, 'DIR_WS');

	$cat_config = array(
    'min_level' =>	1,
		'max_level' =>	2,
		'hide_empty' =>	(CATEGORY_HIDE_EMPTY=='true'?true:false));
						
	function navigation_main($catid = 0, $level = 1) {
		global $cPath, $current_category_id, $cat_config, $db, $box_name;

		$myPathArray = explode('_',$cPath);
		$items = array();
		
		$products = '';
		$count = '';
		
		if ($level < $cat_config['min_level'] || $level > $cat_config['max_level'] )
		  return array();
		
		if(GROUP_CHECK == 'true')
			$group_check = " AND c.group_permission_".$_SESSION['customers_status']['customers_status_id']." = 1 ";

		$categories = $db->db_query("SELECT
											c.categories_id,
											cd.categories_name,
											c.categories_image,
											seo.url_text 
										FROM
											".TABLE_CATEGORIES." c
											INNER JOIN ".TABLE_CATEGORIES_DESCRIPTION." AS cd
                        ON (cd.categories_id = c.categories_id AND cd.language_id = ".(int)$_SESSION['languages_id'].")
											INNER JOIN ".TABLE_SEO_URL." AS seo
                        ON (seo.categories_id = c.categories_id AND seo.language_id = ".(int)$_SESSION['languages_id'].")
										WHERE
											c.parent_id = ".(int)$catid."
										AND
											c.categories_status = 1
											".$group_check."
										ORDER BY
											sort_order", true);
		while(!$categories->EOF) {
		  $items[$categories->fields['categories_id']] = array(
        'level'     => $level,
        'cat_id'    => $categories->fields['categories_id'],
        'cat_name'  => $categories->fields['categories_name'],
        'cat_img'   => $categories->fields['categories_image'],
        'cat_href'  => $categories->fields['url_text'],
        'children'  => array(
          'count'       => 0,
          'items'       => array()
        )
      );
      if ($items[$categories->fields['categories_id']]['cat_img'] != '')
        $items[$categories->fields['categories_id']]['cat_img'] = href_link(DIR_WS_CATEGORIES_DROPDOWN_IMAGES.$items[$categories->fields['categories_id']]['cat_img']);
        
      $sub_items = $box_name($categories->fields['categories_id'], $level+1);
      if (count($sub_items) > 0) {
        $items[$categories->fields['categories_id']]['children'] = array(
          'count'       => count($sub_items),
          'items'       => $sub_items
        );
      }
        
			$categories->MoveNext();
		}
		//echo_e($categories->sql, 'E');
		// echo_e($items, 'E');
		return $items;
	}
						
	$box_smarty->assign('box_name', $box_name);
	$box_smarty->assign('language', $_SESSION['language']);
	$box_smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE.'/');
	$box_smarty->assign('html_tpl_path', CURRENT_TEMPLATE.'/html');
	$box_smarty->assign('BOX_CONTENT', $box_name());
}

$get[] = 'cmg=yes';

if(!$cache)
	$box_content = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_'.$box_name.'.html');
else
	$box_content = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_'.$box_name.'.html', $cache_id);